package cc.lucien.thread;

public class Demo01 {
    public static void main(String[] args) {
        Baozi baozi = new Baozi();
        new Thread(baozi, "窗口1").start();
        new Thread(baozi, "窗口2").start();
        new Thread(baozi, "窗口3").start();
    }
}

class Baozi implements Runnable{
    private int num = 100;
    @Override
    public void run() {
        while (num > 0) {
            try {
                Thread.currentThread().sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (this){
                if (num > 0) {
                    System.out.println(Thread.currentThread().getName()+"卖出一个包子，剩余:" + --num);
                }
            }
        }
    }
}